package com.livepan.file.controller;

import com.livepan.server.BaseController;
import com.livepan.server.error.BusinessException;
import com.livepan.server.response.CommonReturnType;
import com.livepan.server.service.FileService;
import com.livepan.server.service.model.FileModel;
import com.livepan.server.service.model.PageModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/file")
public class FileController extends BaseController {

    public static final String BUSINESS_NAME="文件";

    private static final Logger LOG = LoggerFactory.getLogger(FileController.class);

    @Autowired
    private FileService fileService;

    @ResponseBody
    @RequestMapping("/list")
    public CommonReturnType file(PageModel pageModel) {
        LOG.info("page:" + pageModel.getPage());
        fileService.list(pageModel);
        return CommonReturnType.create(pageModel);
    }

    @ResponseBody
    @RequestMapping("/save")
    public CommonReturnType saveFile(@RequestBody FileModel fileModel) throws BusinessException {
        fileService.save(fileModel);
        return CommonReturnType.create(fileModel);
    }

    @ResponseBody
    @RequestMapping("/delete/{id}")
    public CommonReturnType delete(@PathVariable String id) {
        fileService.delete(id);
        return CommonReturnType.create(null);
    }
}
